/**
 * 
 */
package com.greenx.hello.hrssROME;

import java.io.Reader;
import java.io.StringReader;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.Proxy.Type;

import com.liferay.portal.kernel.util.HttpUtil;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;

/**
 * @author StephenXianweiZhang
 * 
 */
public class HRSSSynd {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SyndFeed feed = null;
		String url = "http://www.carlsonwagonlit.com/en/global/news_and_media/hot_news/rssfeed.xml";
//		String url = "http://www.carlsonwagonlit.com/en/global/news_and_media/hot_news/rssfeed.xml";
		// PROXY MUST BE DELETED, ONLY USED LOCAL TESTING
		Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress(
				"172.28.48.13", 3128));
		try {

			URL url_ = new URL(url);
			url_.openConnection(proxy);
			// com.liferay.portal.kernel.util.HttpUtil will break the connection
			// if it spends more than 5 seconds looking up a location. However,
			// German umlauts do not get encoded correctly. This may be a bug
			// with commons-httpclient or with how FeedParser uses
			// java.io.Reader.

			// Use http://xml.newsisfree.com/feeds/29/629.xml and
			// http://test.domosoft.com/up/RSS to test if German umlauts show
			// up correctly.

			// Reader reader = new StringReader(new String(
			// HttpUtil.URLtoByteArray(url)));

			SyndFeedInput input = new SyndFeedInput();

			//Reader reader = new XmlReader(url_);
			Reader reader = new XmlReader(url_.openConnection(proxy).getInputStream());
			feed = input.build(reader);
			System.out.println(feed.getTitle());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
